/*新增费用*/
import React, { Component } from 'react';
import {
	StyleSheet, Text, View, TouchableOpacity,
	ScrollView, KeyboardAvoidingView, Platform, Image, Alert
} from "react-native";
import { GLOBAL } from '../../../../config/global';
import { style } from '../../../../theme/style';
import { Common } from '../../../../component/common/Common.js';
import { Button } from '../../../../components/form/button';
import { RadiusGroupCpt } from '../_components/RadiusGroupCpt'
import { orderBaseStyle } from '../_common/style.js'
import { FormItem } from '../../../../components/form/formItem'
import OrderAPIService from '../_common/OrderAPIService'
import { CURRENCY } from '../../../../utils/helper';
import ToastUtil from '../../../../utils/toast';
import Utils from '../../../../utils/utils';
import ConstData from '../../../../utils/constData';
import OrderCreateMethods from '../../OrderCreateMethods';
import { DatePicker } from 'react-native-pickers';

const scale = GLOBAL.SCALE;

export class PayPage extends Component {
	static navigationOptions = ({ navigation, navigationOptions }) => {
		return {
			headerTitle: '新增支付',
			headerTintColor: '#272727',
			headerLeft: <Common type="headLeft" onPress={() => { navigation.goBack() }} color='#272727' />,
			headerRight: (<Image style={{ marginLeft: 18 * scale, width: 9 * scale, height: 16 * scale }} source={require('../../../../imgs/goBackEmpty.png')} />),
			headerTitleStyle: {
				flex: 1,
				textAlign: 'center'
			},
			headerStyle: {
				elevation: 0,
				backgroundColor: '#F5F5F5',
				borderBottomWidth: 0,
			},
		}
	};
	constructor(props) {
		super(props);

		let { initData, editData, jsPriceData } = this.props.navigation.state.params || {};
		this.jsPriceData = jsPriceData || {};
		console.log('支付参数', this.props.navigation.state.params)

		this.payTypeData = initData.payTypeData || [] //付款类型
		//资信评级控制
		this.payTypeDataBuy = [];
		this.payTypeDataSell = [];
		this.payTypeData && this.payTypeData.forEach((item) => {
			if (initData.creditLevelSell == 1 && initData.isGoodsFirst) {
				if (item.dictKey == "4") {
					this.payTypeDataSell.push(item);
				}
			} else {
				this.payTypeDataSell = this.payTypeData.slice(0);
			}
			if (initData.creditLevelBuy == 1 && initData.isGoodsFirst) {
				if (item.dictKey == "3" || item.dictKey == "5") {
					this.payTypeDataBuy.push(item);
				}
			} else {
				this.payTypeDataBuy = this.payTypeData.slice(0);
			}
		})

		this.payMethodData = initData.payMethodData || [] //付款方式
		this.payMethodDataBuy = [];
		this.payMethodDataSell = [];
		this.payMethodData && this.payMethodData.forEach((item) => {
			if (initData.creditLevelSell == 1 && initData.isGoodsFirst) {
				if (item.dictKey != "3") {
					this.payMethodDataSell.push(item);
				}
			} else {
				this.payMethodDataSell.push(item);
			}
			if (initData.creditLevelBuy == 1 && initData.isGoodsFirst) {
				if (item.dictKey != "3") {
					this.payMethodDataBuy.push(item);
				}
			} else {
				this.payMethodDataBuy.push(item);
			}
		})


		this.editData = JSON.parse(JSON.stringify(editData)) || {}
		this.orderFlag = initData.orderFlag || {}

		this.state = {
			trustShow: false,
			trustShowBuy: false
		}


		// 授信展示数据  采
		this.showData = {
			limitAmount: '',
			creditEndDate: '',
			isExpired: null,
			accountDay: 0 // 账期天数
		}
		// 授信展示数据  销
		this.showSellData = {
			limitAmount: '',
			creditEndDate: '',
			isExpired: null,
			accountDay: 0 // 账期天数
		}

	}

	async	componentWillMount() {
		let { buyData, sellData } = this.editData || {};
		await this.trustFn(buyData, 'showData');
		await this.trustFn(sellData, 'showSellData');
		await this._getConst();
		this.setState({
			trustShow: this.judgeTrust(sellData.payType, 'S'),
			trustShowBuy: this.judgeTrust(buyData.payType, 'P'),
		})
		//this.trustFn(sellData);
	}

	_getConst = async () => {
		let Const = await ConstData.get();
		console.log('Const', Const);
		if (Const) {
			this.constProportion = Const.ORDER_PRICE_FEE_RATE;
		}
	}


	//付款类型-是否授信初始化
	judgeTrust = (payType, orderType) => {
		let trustShow = false
		//let { tCode } = this.orderFlag;
		//长约执行与长约框架 没有授信
		// if (tCode === 'L' || tCode === 'E') {
		// 	return
		// }
		/*采购:保证金/定金  款到发货
			销售:货到付款  票到付款*/
		if (orderType == 'P') {
			if (payType == '2' || payType == '4') {
				trustShow = true;
			}
		} else if (orderType == 'S') {
			if (payType == '3' || payType == '5') {
				trustShow = true;
			}
		}
		return trustShow
	}

	//授信初始化
	async trustFn(data, type) {
		if (!data.companyId) return
		let trustSend = {
			companyId: data.companyId,
			corpType: type == 'showData' ? '1' : '2',
			orderType: type == 'showData' ? 'P' : 'S'
		}
		let trustData = await OrderAPIService.orderTrust(trustSend);
		if (trustData) {
			let { limitAmount, creditEndDate, accountDay, isExpired } = trustData;
			this[type].limitAmount = limitAmount || '';
			this[type].creditEndDate = creditEndDate || '';
			this[type].isExpired = isExpired || '0';
			this[type].accountDay = accountDay || 0;
		}
	}


	// 单选
	_radiusItemFn = async (itemData, id, indexKey, type) => {
		let lsShow = type == 'buyData' ? 'trustShowBuy' : 'trustShow';
		let lsType = type == 'buyData' ? 'P' : 'S';
		// 付款类型
		this.editData[type][id] = itemData;
		if (type == 'buyData') {
			this.editData[type].payTypeName = this.payTypeDataBuy[indexKey].dictName;
			this.editData[type].payTypeArr = this.payTypeDataBuy[indexKey] && this.payTypeDataBuy[indexKey].comments ? eval(this.payTypeDataBuy[indexKey].comments) : [];
		} else {
			this.editData[type].payTypeName = this.payTypeDataSell[indexKey].dictName;
			this.editData[type].payTypeArr = this.payTypeDataSell[indexKey] && this.payTypeDataSell[indexKey].comments ? eval(this.payTypeDataSell[indexKey].comments) : [];
		}
		this.clearPayTypeData(this.editData[type].payTypeArr, type, 'payType');
		await this._showPriceFn();
		this.setState({
			ls: true,
			[lsShow]: this.judgeTrust(itemData, lsType)
		})
	}

	_radiusItemFn2 = async (itemData, id, indexKey, type) => {
		this.editData[type][id] = itemData;
		this.editData[type].payStyleName = this.payMethodData[indexKey].dictName;
		this.clearPayTypeData(false, type, 'payStyle');
		await this._showPriceFn();
		//this.setState({ ls: true })
	}

	//清空付款类型相关数据
	clearPayTypeData = (payTypeArr, type, strKey) => {
		payTypeArr && payTypeArr.map(item => {
			this.editData[type][item.name] = '';
		})
		//清空
		if (strKey === 'payType') { //授信资金
			this.editData[type].fundCreditFee = null;//授信资金
			this.editData[type].deliveryExpireDays = null;
			this.editData[type].payExpireDays = null;
			this.editData[type].prepayRate = null;
		} else if (strKey === 'payStyle') {
			this.editData[type].fundVoucherFee = null;//票据资金
			this.editData[type].voucherExpireDays = null;//票据期限
		}
	}



	// 定金比例/几天内付款
	_writeCallBack = (objData) => {
		let keyStr = objData.name;
		console.log('key', keyStr)
		let typeStr = objData.type == 'buy' ? 'buyData' : 'sellData';
		this.editData[typeStr][keyStr] = parseFloat(objData.value);
		this.editData[typeStr].payTypeArr = this.editData[typeStr].payTypeArr && this.editData[typeStr].payTypeArr.map(item => {
			if (keyStr === item.name) {
				item.value = objData.value
			}
			return item
		})
		console.log('this.editData---8888', this.editData)
	}

	//新增
	_addFn = () => {
		if (!this._verifyFn()) return;
		this.props.navigation.state.params && this.props.navigation.state.params.callBack(this.editData || null);
		this.props.navigation.goBack();
	}

	// 验证
	_verifyFn = () => {
		let { buyData, sellData } = this.editData || {};
		let { payType, tradeType, payStyle } = sellData;

		let payTypeBuy = buyData.payType;
		let payStyleBuy = buyData.payStyle;

		let { trustShow, trustShowBuy } = this.state;
		let { saleOrder } = this.jsPriceData || {};
		let { orderItemList } = saleOrder || {};
		//付款类型-验证
		if (!payType || !payTypeBuy) {
			ToastUtil.showWarning(`请选择${!payTypeBuy ? '付款类型' : '收款类型'}`);
			return false;
		} else if (tradeType !== 'O') {
			let payTypeArrPass = true;

			//采购
			buyData.payTypeArr && buyData.payTypeArr.map(item => {
				if (buyData[item.name] === '' || buyData[item.name] === null) {
					ToastUtil.showWarning(`请先填写完整付款类型相关数据`);
					payTypeArrPass = false;
					return;
				}
				if (item.name === 'prepayRate' && Number.parseFloat(buyData[item.name]) <= 0) {
					ToastUtil.showWarning(`采购保证金/定金比例必须大于0`);
					payTypeArrPass = false;
					return;
				}
				/* if (trustShowBuy && item.name === 'deliveryExpireDays') {
					if (Number.parseFloat(buyData[item.name]) > Number.parseFloat(this.showData.accountDay)) {
						ToastUtil.showWarning(`本单授信账期必须小于等于授信账户账期天数`);
						payTypeArrPass = false;
						return;
					}
				} */
			})
			if (trustShowBuy) {
				if (Number.parseFloat(buyData.deliveryExpireDays) > Number.parseFloat(this.showData.accountDay)) {
					ToastUtil.showWarning(`本单授信账期必须小于等于授信账户账期天数`);
					payTypeArrPass = false;
					return;
				}
			}


			// 销售
			sellData.payTypeArr && sellData.payTypeArr.map(item => {
				if (sellData[item.name] === '' || sellData[item.name] === null) {
					ToastUtil.showWarning(`请先填写完整收款类型相关数据`);
					payTypeArrPass = false;
					return;
				}
				if (item.name === 'prepayRate' && Number.parseFloat(sellData[item.name]) <= 0) {
					ToastUtil.showWarning(`销售保证金/定金比例必须大于0`);
					payTypeArrPass = false;
					return;
				}
				if (trustShow && item.name === 'payExpireDays') {
					if (Number.parseFloat(sellData[item.name]) > Number.parseFloat(this.showSellData.accountDay)) {
						ToastUtil.showWarning(`付款天数必须小于等于账期天数`);
						payTypeArrPass = false;
						return;
					}
				}
			})

			if (!payTypeArrPass) return payTypeArrPass
		}

		//采购 - 授信账期
		if (OrderCreateMethods._isSxzq('P', buyData.payType)) {
			if (Utils.isEmpty(buyData.deliveryExpireDays)) {
				ToastUtil.showWarning('请输入采购的预付(授信)账期天数');
				return false;
			} else if (isNaN(buyData.deliveryExpireDays)) {
				ToastUtil.showWarning('采购的预付(授信)账期天数不是有效数字');
				return false;
			} else if (parseFloat(buyData.deliveryExpireDays) < 0) {
				ToastUtil.showWarning('采购的预付(授信)账期天数必须大于等于0');
				return false;
			}
		}

		//销售 - 授信账期
		if (OrderCreateMethods._isSxzq('S', sellData.payType)) {
			if (Utils.isEmpty(sellData.deliveryExpireDays)) {
				ToastUtil.showWarning('请输入销售的赊销(授信)账期天数');
				return false;
			} else if (isNaN(sellData.deliveryExpireDays)) {
				ToastUtil.showWarning('销售的赊销(授信)账期天数不是有效数字');
				return false;
			} else if (parseFloat(sellData.deliveryExpireDays) < 0) {
				ToastUtil.showWarning('销售的赊销(授信)账期天数必须大于等于0');
				return false;
			}
		}

		//一级企业一级商品付款天数须小于等于3天
		if (sellData.companyCreditLevel == 1 && orderItemList && orderItemList.length && orderItemList.some(item => { return item.transLevel == 1; })) {
			if (sellData.payExpireDays && sellData.payExpireDays > 3) {
				ToastUtil.showWarning('一级企业一级商品付款天数须小于等于3天');
				return false;
			}
		}





		//付款(收款)方式-验证
		if (!payStyle || !payStyleBuy) {
			ToastUtil.showWarning(`请选择${!payStyleBuy ? '付款方式' : '收款方式'}`);
			return false;
		}

		//资金（授信）
		if (this._isZjcbSx('P') && !buyData.fundCreditFee && buyData.fundCreditFee != 0) {
			ToastUtil.showWarning('请输入采购的资金（授信）');
			return false;
		}
		//资金（授信）
		if (this._isZjcbSx('S') && !sellData.fundCreditFee && sellData.fundCreditFee != 0) {
			ToastUtil.showWarning('请输入销售的资金（授信）');
			return false;
		}

		//资金（票据）
		if (this._isZjcbPj(sellData) && !sellData.fundVoucherFee && sellData.fundVoucherFee != 0) {
			ToastUtil.showWarning('请输入销售的资金（票据）');
			return false;
		}
		//资金（票据）
		if (this._isZjcbPj(sellData) && !sellData.voucherExpireDays && sellData.voucherExpireDays != 0) {
			ToastUtil.showWarning('请输入销售的票据期限-天数');
			return false;
		}

		return true;
	}


	//1,判断是否有 资金 授信 字段
	_isZjcbSx = (orderType) => {
		let { buyData, sellData } = this.editData || {};
		let result = false;
		let payType = orderType == 'S' ? sellData.payType : buyData.payType;
		if ((orderType == "S" && (payType == '5' || payType == '3')) || (orderType == "P" && (payType == '2' || payType == '4'))) {
			result = true;
		}
		return result;
	}

	//2.资金 授信
	_zjcbSx = (infoObj, orderType) => {
		let { payType, fundCreditFee } = infoObj || {};
		if ((orderType == "S" && (payType == '5' || payType == '3')) || (orderType == "P" && (payType == '2' || payType == '4'))) {
			return <FormItem editable={false} border={false} iconText={`资金（授信）=加权平均单价*${this.constProportion}%*${orderType == "S" ? '本单货到或票到天数' : '本单款到天数'}/365天`} keyboardType={'numeric'} handleCallBack={(text) => { this._writeCallBack({ name: 'fundCreditFee', value: text, type: orderType == "S" ? 'sell' : 'buy' }) }} labelStyle={orderBaseStyle.labelStyle} sizeType={'small'} placeHolder={'公式'} label={'资金(授信)'} value={fundCreditFee} rightText={'元/吨'} rightTextStyle={{ fontSize: 12 * scale, color: '#333' }} inputStyle={{ textAlign: 'center' }} type={'input'} />
		}
		return null;
	}



	//1.判断是否有 资金 票据
	_isZjcbPj = infoObj => {
		let result = false;
		let { payStyle } = infoObj || {};
		if (payStyle == '2' || payStyle == '3') {
			result = true;
		}
		return result;
	}

	//3.资金 票据
	_zjcbPj = infoObj => {
		let { fundVoucherFee, voucherExpireDays } = infoObj || {};
		if (this._isZjcbPj(infoObj)) {
			return <View style={orderBaseStyle.fklxBox}>
				<FormItem onBlurFn={() => { this._onBlurFn('voucherExpireDays', 'S') }} key={new Date().getTime() + Math.random()} keyboardType={'numeric'} handleCallBack={(text) => { this._writeCallBack({ name: 'voucherExpireDays', value: text, type: 'sell' }) }} labelStyle={orderBaseStyle.labelStyle} required={true} sizeType={'small'} placeHolder={'请输入'} label={'票据期限'} value={voucherExpireDays} rightText={'天'} rightTextStyle={{ fontSize: 12 * scale, color: '#333' }} inputStyle={{ textAlign: 'center' }} type={'input'} />
				<FormItem editable={false} key={new Date().getTime()} iconText={`资金（票据）=销加权平均单价*${this.constProportion}%*销票据期限/365）`} keyboardType={'numeric'} labelStyle={orderBaseStyle.labelStyle} required={true} sizeType={'small'} placeHolder={'公式'} label={'资金(票据)'} value={fundVoucherFee} rightText={'元/吨'} rightTextStyle={{ fontSize: 12 * scale, color: '#333' }} inputStyle={{ textAlign: 'center' }} type={'input'} />
			</View>
		}
		return null;
	}


	_onBlurFn = async (onBlurStr, type) => {
		let { trustShow } = this.state;
		let { saleOrder, purchaseOrder } = this.jsPriceData || {};
		let saleGoods = saleOrder && saleOrder.orderItemList || [];
		let buyGoods = purchaseOrder && purchaseOrder.orderItemList || [];
		OrderCreateMethods._payExpireDays({ orderFlag: { orderType: type, tCode: 'C' }, orderInfo: type == 'S' ? this.editData.sellData : this.editData.buyData, orderItemList: type == 'S' ? saleGoods : buyGoods });
		if ((this._isZjcbSx(type) && ((type == 'P' && onBlurStr == 'deliveryExpireDays') || (type == 'S' && onBlurStr == 'payExpireDays'))) || onBlurStr == 'voucherExpireDays') {
			if (type == 'S' && onBlurStr == 'payExpireDays') { // 赊销(账期)天数 根据票到/货到多少天联动
				this.editData.sellData.deliveryExpireDays = this.editData.sellData.payExpireDays;
				if (trustShow) {
					if (Number.parseFloat(this.editData.sellData.payExpireDays) > Number.parseFloat(this.showSellData.accountDay)) {
						Alert.alert('提示', `授信账期时间需小于等于授信账期${this.showSellData.accountDay}天`, [
							{ text: '知道了', onPress: () => { console.log('确认') } }
						])
					}
				}
			}
			await this._showPriceFn();
			this.props.navigation.state.params.callBack && this.props.navigation.state.params.callBack(this.editData);
		} else {
			console.log('不走..........')
		}
	}


	// 底部弹框 价格 费用展示
	_showPriceFn = async () => {

		let { buyData, sellData } = this.editData || {};
		this.jsPriceData.saleOrder.orderInfo = sellData;
		this.jsPriceData.purchaseOrder.orderInfo = buyData;

		let tCode = 'C';
		//是否满足调用接口

		let responseData = await OrderAPIService.showPrice(this.jsPriceData);
		let lsData = JSON.stringify(responseData);
		console.log('计算放回------99999999', lsData)
		//根据结果 数据返回
		if (responseData) {
			let { orderPriceItemList, orderPriceInfo } = responseData || {};

			//多商品
			orderPriceItemList && orderPriceItemList.forEach((item, index) => {
				this.jsPriceData.saleOrder.orderItemList[index].barePrice = item.barePrice; // 裸价
				this.jsPriceData.saleOrder.orderItemList[index].pocketPrice = item.pocketPrice; //落代价
				if (tCode == 'C') {
					this.jsPriceData.purchaseOrder.orderItemList[index].barePrice = item.purchaseOrderItem.barePrice; // 裸价
					this.jsPriceData.purchaseOrder.orderItemList[index].pocketPrice = item.purchaseOrderItem.pocketPrice; //落代价
				}
			})

			// 根据计算结果 处理相对应的数据
			// 筛选字段
			this.jsPriceData.saleOrder.orderInfo.fundVoucherFee = orderPriceInfo.fundVoucherFee;
			this.jsPriceData.saleOrder.orderInfo.fundCreditFee = orderPriceInfo.fundCreditFee;
			this.jsPriceData.saleOrder.orderInfo.voucherExpireDays = orderPriceInfo.voucherExpireDays;
			if (tCode == 'C') {//
				this.jsPriceData.purchaseOrder.orderInfo.fundVoucherFee = orderPriceInfo.purchaseOrderInfo && orderPriceInfo.purchaseOrderInfo.fundVoucherFee;
				this.jsPriceData.purchaseOrder.orderInfo.fundCreditFee = orderPriceInfo.purchaseOrderInfo && orderPriceInfo.purchaseOrderInfo.fundCreditFee;
				this.jsPriceData.purchaseOrder.orderInfo.voucherExpireDays = orderPriceInfo.purchaseOrderInfo && orderPriceInfo.purchaseOrderInfo.voucherExpireDays;

			}
		}
		this.setState({
			ls: true
		})
	}

	_sxzqBlurFn = async (type) => {
		let { trustShowBuy } = this.state;
		let { buyData, sellData } = this.editData || {};
		let { deliveryExpireDays } = buyData || {};
		if (type == 'buyData') {
			await this._showPriceFn();
			this.props.navigation.state.params.callBack && this.props.navigation.state.params.callBack(this.editData);
		}
		//
		if (trustShowBuy && type == 'buyData' && (Number.parseFloat(deliveryExpireDays) > Number.parseFloat(this.showData.accountDay))) {
			Alert.alert('提示', `采购授信账期时间需小于等于授信账期${this.showData.accountDay}天`, [
				{ text: '知道了', onPress: () => { console.log('确认') } }
			])
		}
		OrderCreateMethods._sxzqValidation(this.editData[type].deliveryExpireDays, type == 'buyData' ? 'P' : 'S');
	}

	//授信账期
	_sxzq = (orderInfo, orderType, type) => {
		let { deliveryExpireDays, payType } = orderInfo || {};
		if (OrderCreateMethods._isSxzq(orderType, payType)) {
			return <FormItem
				onBlurFn={() => { this._sxzqBlurFn(orderType === 'P' ? 'buyData' : 'sellData') }}
				iconText={`该天数为本单授信账期，系统会以此天数计算授信订单逾期日`}
				keyboardType={'numeric'}
				handleCallBack={(text) => { this._writeCallBack({ name: 'deliveryExpireDays', value: text, type }) }}
				labelStyle={orderBaseStyle.labelStyle}
				required={true}
				sizeType={'small'}
				placeHolder={orderType == 'S' ? '联动' : '请输入'}
				label={`${orderType == 'P' ? '预付' : '赊销'}(授信)账期`}
				value={Utils.numberToString(deliveryExpireDays)}
				rightText={'天'}
				rightTextStyle={{ fontSize: 12 * scale, color: '#333' }}
				inputStyle={{ textAlign: 'center' }}
				editable={orderType == 'S' ? false : true}
				type={'input'} />
		}
		return null;
	}


	render() {
		let { buyData, sellData } = this.editData || {};
		let timeStamp = new Date().getTime();
		let { trustShow, trustShowBuy } = this.state;
		return (
			<KeyboardAvoidingView style={styles.container} behavior={Platform.OS === 'ios' ? 'padding' : null} keyboardVerticalOffset={74}>
				<ScrollView showsVerticalScrollIndicator={false} keyboardShouldPersistTaps={'handled'} style={{
					paddingLeft: 12 * scale,
					paddingRight: 12 * scale
				}}>
					<View style={styles.body}>

						<View style={styles.borderWrapBox}>
							<Text style={styles.borderTips}>采购</Text>
							<View style={[styles.borderWrap]}>
								<RadiusGroupCpt data={{
									title: '付款类型',
									required: true,
									listData: this.payTypeDataBuy,
									selectedKey: buyData.payType,
									_radiusItemFn: this._radiusItemFn,
									textStyleBox: orderBaseStyle.textStyle,
									id: 'payType',
									type: 'buyData'
								}} />
								<View style={orderBaseStyle.fklxBox}>
									{
										buyData.payTypeArr && buyData.payTypeArr.map((item, index) => {
											return <View key={index} style={orderBaseStyle.showOrderTipBox}>
												{
													item.name === 'prepayAmtBalanceDate' ? <FormItem styleObj={{ size: 'small', valueStyle: { width: 100 * scale, textAlign: 'center' } }} rightIconStyle={{ marginLeft: 5 * scale }} type={'select'} label={item.title} value={buyData.prepayAmtBalanceDate} placeHolder={'请选择时间'} handleCallBack={() => { this.endTime = "P"; this.DatePicker.show(); }} required />
														: <FormItem onBlurFn={() => { this._onBlurFn(item.name, 'P') }} key={timeStamp + index} keyboardType={'numeric'} handleCallBack={(text) => { this._writeCallBack({ name: item.name, value: text, type: 'buy' }) }} labelStyle={orderBaseStyle.labelStyle} required={true} sizeType={'small'} placeHolder={'请输入'} label={item.title} value={item.value} rightText={item.text} rightTextStyle={{ fontSize: 12 * scale, color: '#333' }} inputStyle={{ textAlign: 'center' }} type={'input'} />
												}
											</View>
										})
									}
									{this._sxzq(buyData, 'P', 'buy')}
									{this._zjcbSx(buyData, 'P')}
								</View>
								{trustShowBuy ? <View style={orderBaseStyle.goodsZhi}><Text style={orderBaseStyle.address}>授信可用余额: ￥{CURRENCY.format(this.showData.limitAmount)}元   <Text style={orderBaseStyle.address}>有效期至: {this.showData.creditEndDate || ''}</Text>   <Text style={orderBaseStyle.address}>账期:{this.showData.accountDay || 0}天</Text>  <Text onPress={() => { this.props.navigation.navigate('BillPage', { companyId: buyData.companyId, companyName: buyData.companyName, corpType: buyData.orderType == 'P' ? 1 : 0 }) }} style={[orderBaseStyle.billDetail]}>[查看明细]</Text></Text></View> : null}
								<RadiusGroupCpt data={{
									title: '付款方式',
									required: true,
									listData: this.payMethodDataBuy,
									selectedKey: buyData.payStyle,
									textStyleBox: orderBaseStyle.textStyle,
									_radiusItemFn: this._radiusItemFn2,
									id: 'payStyle',
									type: 'buyData'
								}} />
							</View>
						</View>

						<View style={styles.borderWrapBox}>
							<Text style={[styles.borderTips, { color: '#45780A' }]}>销售</Text>
							<View style={[styles.borderWrap, { borderColor: '#45780A' }]}>

								<RadiusGroupCpt data={{
									title: '收款类型',
									required: true,
									listData: this.payTypeDataSell,
									selectedKey: sellData.payType,
									_radiusItemFn: this._radiusItemFn,
									textStyleBox: orderBaseStyle.textStyle,
									id: 'payType',
									type: 'sellData'
								}} />
								<View style={orderBaseStyle.fklxBox}>
									{
										sellData.payTypeArr && sellData.payTypeArr.map((item, index) => {
											return <View key={index} style={orderBaseStyle.showOrderTipBox}>
												{
													item.name === 'prepayAmtBalanceDate' ? <FormItem styleObj={{ size: 'small', valueStyle: { width: 100 * scale, textAlign: 'center' } }} rightIconStyle={{ marginLeft: 5 * scale }} type={'select'} label={item.title} value={sellData.prepayAmtBalanceDate} placeHolder={'请选择时间'} handleCallBack={() => { this.endTime = "S"; this.DatePicker.show(); }} required />
														: <FormItem onBlurFn={() => { this._onBlurFn(item.name, 'S') }} key={timeStamp + index} keyboardType={'numeric'} handleCallBack={(text) => { this._writeCallBack({ name: item.name, value: text, type: 'sell' }) }} labelStyle={orderBaseStyle.labelStyle} required={true} sizeType={'small'} placeHolder={'请输入'} label={item.title} value={item.value} rightText={item.text} rightTextStyle={{ fontSize: 12 * scale, color: '#333' }} inputStyle={{ textAlign: 'center' }} type={'input'} />
												}
											</View>
										})
									}
									{this._sxzq(sellData, 'S', 'sell')}
									{this._zjcbSx(sellData, 'S')}
								</View>
								{trustShow ? <View style={orderBaseStyle.goodsZhi}><Text style={orderBaseStyle.address}>授信可用余额: ￥{CURRENCY.format(this.showSellData.limitAmount)}元   <Text style={orderBaseStyle.address}>有效期至: {this.showSellData.creditEndDate || ''}</Text>   <Text style={orderBaseStyle.address}>账期:{this.showSellData.accountDay || 0}天</Text>  <Text onPress={() => { this.props.navigation.navigate('BillPage', { companyId: sellData.companyId, companyName: sellData.companyName, corpType: sellData.orderType == 'P' ? 1 : 0 }) }} style={[orderBaseStyle.billDetail]}>[查看明细]</Text></Text></View> : null}
								<RadiusGroupCpt data={{
									title: '收款方式',
									required: true,
									listData: this.payMethodDataSell,
									selectedKey: sellData.payStyle,
									_radiusItemFn: this._radiusItemFn2,
									textStyleBox: orderBaseStyle.textStyle,
									id: 'payStyle',
									type: 'sellData'
								}} />
								{this._zjcbPj(sellData)}
							</View>
						</View>

					</View>
				</ScrollView>
				<View style={styles.btnWarp}>
					<Button text={'添加'} width={300} height={34} onPress={this._addFn} />
				</View>
				<DatePicker
					HH={false}
					mm={false}
					ss={false}
					startYear={2000}
					endYear={2200}
					onPickerConfirm={(value) => {
						if (this.endTime === "P") {
							this.editData.buyData.prepayAmtBalanceDate = OrderCreateMethods._endPayTime(value);
						} else {
							this.editData.sellData.prepayAmtBalanceDate = OrderCreateMethods._endPayTime(value);
						}

						this.setState({ ls: true })
					}}
					onPickerCancel={() => {
						console.log('cancel');
					}}
					ref={ref => this.DatePicker = ref} />

			</KeyboardAvoidingView>
		)
	}
}
const styles = StyleSheet.create({
	container: {
		flex: 1,
		backgroundColor: '#F5F5F5',
	},
	body: {
		flex: 1,
		backgroundColor: '#fff',
		borderRadius: 4 * scale,
		paddingTop: 10 * scale,
		paddingBottom: 20 * scale
	},
	btnWarp: {
		height: 72 * scale,
		flexDirection: 'row',
		alignItems: 'center',
		justifyContent: 'center',
	},
	borderWrapBox: {
		position: 'relative',
	},
	borderWrap: {
		borderWidth: 1 * scale,
		borderStyle: 'solid',
		borderColor: '#F5A726',
		marginTop: 20 * scale,
		marginBottom: 2 * scale,
		borderRadius: 4 * scale,
		paddingTop: 10 * scale,
		paddingBottom: 10 * scale,
	},
	borderTips: {
		position: 'absolute',
		backgroundColor: '#fff',
		height: 18 * scale,
		width: 52 * scale,
		lineHeight: 18 * scale,
		textAlign: 'center',
		top: 12 * scale,
		left: 150 * scale,
		fontSize: 13 * scale,
		color: '#F5A726',
		zIndex: 1
	},
})
